<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template_bill.xhtml">

        <ui:define name="title">
            <h:outputText value="عرض الفاتورة"></h:outputText>
        </ui:define>

        <ui:define name="body">

            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>

            <h:form>
                <ul class="thumbnails">

                    <li class="span3">
                        <p:commandLink update=":myform:itemID" action="#{exporterBillItemsController.meat}" value="لحوم" styleClass="button"></p:commandLink>
                    </li>

                    <li class="span3">
                        <p:commandLink  update=":myform:itemID" action="#{exporterBillItemsController.nonMeat}" value="غير لحوم " styleClass="button1"><img src="img/notmeat.jpg" width="220" height="80" title="غير لحوم"/></p:commandLink>
                    </li>

                    <li class="span3">
                        <p:commandLink update=":myform:itemID" action="#{exporterBillItemsController.checken}" value="فراخ" styleClass="button2"><img src="img/chicken.jpg" width="220" height="80"  title="فراخ"/></p:commandLink>
                    </li>

                    <li class="span3">
                        <p:commandLink update=":myform:itemID" action="#{exporterBillItemsController.vegtable}" value="منتجات زراعية " styleClass="button3"><img src="img/beans.jpg" width="220" height="80" title="منتجات زراعية"/></p:commandLink>
                    </li>

                </ul>
            </h:form>


            <h:form id="myform">
                <div id="Bill">
                    <div class="form-inline well">
                        <label style="padding-left: 10px;" for="input04">رقم الفاتورة</label>
                        <h:inputText size="5" value="#{exporterBillItemsController.billNumber}" id="input04" readonly="true" /> 

                        <label style="padding-right: 20px; padding-left: 32px;" for="input04">رقم الدفتر </label>
                        <h:inputText size="5" value="#{exporterBillItemsController.docNumber}" readonly="true"/> 

                        <label style="padding-right: 20px; padding-left: 32px;" for="input05">التاريخ</label>
                        <h:outputText value="#{exporterBillItemsController.CDate}"/>

                        <div class="clear"></div>

                        <center>
                            <label style="padding-left: 15px;" for="input06">اسم المورد</label>
                            <h:inputText  value="#{exporterBillItemsController.exporterName}" readonly="true"/> 

                            <h:panelGroup   id="Customer" >
                                <label style="padding-left: 15px;padding-right: 20px;" for="input06"  >الرصيد</label>        
                                <h:panelGroup rendered="#{!(exporterBillItemsController.balanceBeforeBill > 0)}">
                                    <span class="label label-info" >    
                                        #{(exporterBillItemsController.balanceBeforeBill)*-1 }
                                    </span>
                                </h:panelGroup>

                                <h:panelGroup rendered="#{exporterBillItemsController.balanceBeforeBill > 0}" >
                                    <span class="label label-info" >    
                                        #{exporterBillItemsController.balanceBeforeBill}
                                    </span>
                                </h:panelGroup>

                                <label style="padding-left: 15px;" ></label>
                                <h:panelGroup rendered="#{!(exporterBillItemsController.balanceBeforeBill > 0)}">
                                    دائن 
                                </h:panelGroup>
                                <h:panelGroup rendered="#{exporterBillItemsController.balanceBeforeBill > 0}">
                                    مدين 
                                </h:panelGroup>
                            </h:panelGroup>
                        </center>

                    </div>
                </div>

                <div class="form-inline well">
                    <label style="padding-right: 50px; padding-left: 10px;" for="itemID">المنتج</label>
                    <h:selectOneMenu id="itemID"  value="#{exporterBillItemsController.selectedsubItem}" title="SubItem"  valueChangeListener="#{exporterBillItemsController.listenItemchanged}" immediate="true" styleClass="chosen">
                        <f:selectItems value="#{exporterBillItemsController.items}"/>
                        <f:ajax render="countryID" listener="#{exporterBillItemsController.itemListener}" event="valueChange"/>
                    </h:selectOneMenu>

                    <label style="padding: 10px;" for="countryID">البلد</label>
                    <h:selectOneMenu id="countryID" value="#{exporterBillItemsController.selectedCountry}" title="SubItem" styleClass = "chosen" >
                        <f:selectItems value="#{exporterBillItemsController.countries}"/>
                        <f:ajax render="factoryID" listener="#{exporterBillItemsController.itemListener}" event="valueChange"/>
                    </h:selectOneMenu>

                    <label style="padding: 10px;" for="factoryID">المصنع</label>
                    <h:selectOneMenu id="factoryID" value="#{exporterBillItemsController.factory}" title="factory" styleClass = "chosen">
                        <f:selectItems value="#{exporterBillItemsController.facoris}"/>
                    </h:selectOneMenu>

                    <div class="clear"></div>

                    <label style="padding: 10px;" for="input02">العدد</label>
                    <h:inputText size="10" value="#{exporterBillItemsController.total_Number}" id="input01"/>

                    <label style="padding-right:10px; padding-left: 10px;" for="input01">الوزن</label>
                    <h:inputText size="10" value="#{exporterBillItemsController.totalKg}" id ="input02" />

                    <h:commandButton value="احسب" action="#{exporterBillItemsController.calculate}" />

                    <label style="padding: 10px;" for="input03">سعر الوحدة</label>
                    <h:inputText size="10" value="#{exporterBillItemsController.unite_price}" id="input03" >
                        <f:ajax execute="@form" render="totalprice" event="blur" listener="#{exporterBillItemsController.itemListener}"/>
                    </h:inputText>

                    <center>

                        <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">  
                            <h:outputText value="حالة المنتج" />
                            <p:selectOneRadio  id="itemStatus" value="#{exporterBillItemsController.billItemStatus}" >  
                                <f:selectItem itemValue="Regular" itemLabel="عادى"/>
                                <f:selectItem itemValue="ProductExecution" itemLabel="إعدام"/>
                            </p:selectOneRadio>  
                        </h:panelGrid>

                        <label style="padding: 10px;"> الإجمالى</label> 
                        <span class="label label-info">
                            <h:outputText id ="totalprice" value="#{exporterBillItemsController.total_price}"/>
                        </span>

                        <div class="clear"></div>

                        <p:commandLink update=":myform2:add_item2,:myform3:tot" value="اضافه" action="#{exporterBillItemsController.add_item()}"></p:commandLink>
                    </center>

                </div>
            </h:form>

            <h:form id="myform2"> 
                <h:dataTable value="#{exporterBillItemsController.add_Item}" id="add_item2" var="added_item" styleClass = "table table-condensed table-striped">

                    <h:column>
                        <f:facet name="header"> المنتج  </f:facet>
                        #{added_item.item}
                    </h:column>

                    <h:column>
                        <f:facet name="header"> المصنع  </f:facet>
                        #{added_item.factory}
                    </h:column>

                    <h:column>
                        <f:facet name="header"> البلد  </f:facet>
                        #{added_item.country}
                    </h:column>

                    <h:column>
                        <f:facet name="header"> العدد  </f:facet>
                        <h:inputText value="#{added_item.item_count}" size="5" rendered="#{added_item.editable}" />
                        <h:outputText value="#{added_item.item_count}" rendered="#{not added_item.editable}" />
                    </h:column>

                    <h:column>
                        <f:facet name="header"> الوزن   </f:facet>
                        <h:inputText value="#{added_item.item_quantity}" size="5" rendered="#{added_item.editable}" />
                        <h:outputText value="#{added_item.item_quantity}" rendered="#{not added_item.editable}" />
                    </h:column>

                    <h:column>
                        <f:facet name="header"> سعر الوحدة  </f:facet>
                        <h:inputText value="#{added_item.unit_price}" size="5" rendered="#{added_item.editable}" />
                        <h:outputText value="#{added_item.unit_price}" rendered="#{not added_item.editable}" />
                    </h:column>

                    <h:column>
                        <f:facet name="header"> الاجمالي   </f:facet>
                        <h:outputText value=" #{added_item.totoal_price}"  />
                    </h:column> 

                    <h:column >
                        <f:facet name="header"> حالة المنتج </f:facet>
                        <h:outputText value="إعدام" rendered="#{added_item.billItemStatus=='ProductExecution' and not added_item.editable}" />
                        <h:outputText value="عادى" rendered="#{added_item.billItemStatus=='Regular' and not added_item.editable}" />
                        <h:outputText value="عادى" rendered="#{added_item.billItemStatus==null and not added_item.editable}" />

                        <p:selectOneRadio  id="itemStatus" value="#{added_item.billItemStatus}" rendered="#{added_item.editable}">  
                            <f:selectItem itemValue="Regular" itemLabel="عادى"/>
                            <f:selectItem itemValue="ProductExecution" itemLabel="إعدام"/>
                        </p:selectOneRadio>  
                    </h:column>

                    <h:column>
                        <f:facet name="header">Action</f:facet>
                        <h:commandButton value="تعديل" action="#{exporterBillItemsController.editAction(added_item)}" rendered="#{not added_item.editable}" styleClass ="btn btn-primary" />
                        <h:commandButton value="حفظ" action="#{exporterBillItemsController.saveAction(added_item)}" rendered="#{added_item.editable}" styleClass ="btn btn-primary" />
                        <h:commandButton value="مسح" action="#{exporterBillItemsController.deleteAction(added_item)}" styleClass ="btn btn-primary" />
                    </h:column>

                </h:dataTable>
            </h:form>

            <div class="clear"></div>
            <div class="form-inline well">
                <h:form id="myform3">

                    <label style="padding-right:10px; padding-left: 10px;" for="tot">الاجمالى   </label> 
                    <h:inputText size="10" value="#{exporterBillItemsController.billTotal}" id="tot" readonly="true"/>

                    <label style="padding-right:10px; padding-left: 10px;" for="pay">المبلغ المدفوع </label>
                    <h:inputText size="10" value="#{exporterBillItemsController.paied}" id="pay">
                        <f:ajax execute="@form" render="rem balanceAfter" event="blur" listener="#{exporterBillItemsController.itemListener}"/>
                    </h:inputText>

                    <label style="padding-right:10px; padding-left: 10px;" for="rem">الباقى    </label> 
                    <h:inputText size="10" value="#{exporterBillItemsController.bill_reminder}" id="rem" readonly="true"/>

                    <div class="clear"></div>

                    <label style="padding-right:10px; padding-left: 10px;" for="disc">الخصم  </label>
                    <h:inputText size="10" value="#{exporterBillItemsController.discount}" id="disc">
                        <f:ajax execute="@form" render="tot rem balanceAfter" event="blur" listener="#{exporterBillItemsController.itemListener}"/>
                    </h:inputText>

                    <h:selectBooleanCheckbox value="#{exporterBillItemsController.noExistence}" id="non"></h:selectBooleanCheckbox>
                    <label style="padding-right:10px; padding-left: 10px;" for="non">تالف  </label>

                    <h:panelGroup id ="balanceAfter">
                        <label style="padding-left: 15px;padding-right: 20px;" for="input06">الرصيد بعد الفاتوره</label>        

                        <label style="padding-left: 15px;" ></label>
                        <h:panelGroup rendered="#{exporterBillItemsController.balanceAfterBill > 0}">
                            <span class="label label-info" >   
                                <h:outputText  value="#{exporterBillItemsController.balanceAfterBill}"/>
                            </span>
                            لينا

                        </h:panelGroup>
                        <h:panelGroup rendered="#{! (exporterBillItemsController.balanceAfterBill > 0)}">
                            <span class="label label-info" >   
                                <h:outputText  value="#{exporterBillItemsController.balanceAfterBill*-1}"/>
                            </span>
                            مدين                        
                        </h:panelGroup>

                    </h:panelGroup>

                    <div class="clear"></div>

                    <center>
                        <h:commandButton value="حفظ" action="#{exporterBillItemsController.confirmValues()}" styleClass="btn btn-primary"/>
                        <h:outputText value="  "/>
                        <h:commandButton value="طباعة" onclick="print('Bill','item')" styleClass = "btn btn-primary"/>
                        <h:outputText value="  "/>
                        <h:commandButton action="ExporterBills"  value="رجوع" styleClass = "btn btn-primary" immediate="true"/>
                    </center>
                </h:form>
            </div>
        </ui:define>
    </ui:composition>
</html>